package com.conan.mvc.controller;

import com.conan.mvc.bean.User;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Arrays;


/**
 * @version 加油！！！
 * @Description
 * @Author 谷藤新一GYC
 * @Date 2022/10/23 - 20:36
 */
@Controller
public class ParamController {

    @RequestMapping("/textServletAPI")
    //形参位置的request表示当前请求
    public String textServletAPI(HttpServletRequest request){
        HttpSession session = request.getSession();
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        System.out.println("username："+username+"password:"+password);
        return "success";
    }

    @RequestMapping("/testParam")
    public String testParam(
            @RequestParam(value = "user_name",required = true,defaultValue = "谷艺彩") String username,
            String password,
            String[] hobby,
            @RequestHeader(value = "sayHaHa",required = true,defaultValue = "haHa") String host,
            @CookieValue("JSESSIONID") String JSESSION){
        //若请求参数中出现多个同名的请求参数,可以在控制方法的形参位置设置字符串类型或字符串数组接收此请求参数
        //若使用字符串类型的形参,最终结果为请求参数的每一个值之间使用逗号进行拼接
        System.out.println("username："+username+"\npassword:"+password+"\nhobby:"+ Arrays.toString(hobby));
        System.out.println("host:"+host);
        System.out.println("session:"+JSESSION);
        return "success";

    }
    @RequestMapping("/testBean")
    public String testBean(User user){
        System.out.println(user);
        return "success";
    }



}
   